﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.04.18
 * 描 述：查看模型计算结果
 */

var keyValue = request('modelId');
var defaultCompanyId = request('companyId');
var defaultKjnd = request('defaultKjnd');
var warnId = request('warnId');


var userdefault = {};
var selectedRow;
var step2List = [];

var bootstrap = function ($, learun) {
    "use strict";

    var jfGrid1 = null;

    // 保存数据
    var acceptClick = function (type) {// 0保存并新增 1保存

    };

    var page = {
        init: function () {
            userdefault = learun.clientdata.get(['usersetting']);
            if(!!defaultCompanyId) {
                userdefault.companyId = defaultCompanyId;
            }
            page.bind();
            $("#kjnd").val(defaultKjnd);
            page.initData();
        },
        bind: function () {
            // 优化滚动条
            $('.lr-layout-wrap').lrscroll();
            $('#multiple_condition_query').lrMultipleQuery(function (queryJson) {
                // 调用后台查询
                // queryJson 查询条件
                page.search(queryJson);

            }, 200, 888);

            // 公司选择
            $('#companyId').lrselect({
                type: 'tree',
                placeholder: '==全部单位==',
                height: 300,
                maxHeight: 300,
                // 是否允许搜索
                allowSearch: true,
            });
            $('#companyId').lrselectRefresh({
                // 访问数据接口地址
                url: config.base_server() + 'companys/tree?access_token=' + config.getToken().access_token,
                // 访问数据接口参数
                param: {parentId: '0'}
            }).lrselectSet(userdefault.companyId);

            // 整改
            $('#btn_deal').on('click', function () {
                learun.layerForm({
                    id: 'warn_deal' + keyValue,
                    title: '告警整改',
                    url: config.webportal_server + '/pages/workflow/wfmyTask/custmerWorkFlowForm.html?keyValue=' + keyValue + '&modelId=' + keyValue + '&warnId=' + warnId + '&shcemeCode=warn_deal&tabIframeId=5456a5f791844dbaaa1474af2a70e8db&type=0',
                    width: 1000,
                    height: 800,
                    maxmin: true,
                    btn: null
                });
            });
            // 忽略
            $('#btn_ingore').on('click', function () {
                learun.layerForm({
                    id: 'warn_ingore' + keyValue,
                    title: '告警忽略',
                    url: config.webportal_server + 'pages/finance/audit_warn/ignore/form.html?warnId=' + warnId + '&access_token=' + config.getToken().access_token,
                    width: 450,
                    height: 280,
                    callBack: function (id) {
                        return top[id].acceptClick();
                    }
                });
            });

            //下载
            $('#btn_download').on('click', function () {
               var companyId = $("#companyId").lrselectGet();
               var kjnd = $("#kjnd").val();
               location.href = config.base_server() + 'auditmodels/exportExcel?modelId=' + keyValue + '&companyId=' + companyId + '&kjnd=' + kjnd + '&warnId=' + warnId + '&access_token=' + config.getToken().access_token;
            });

            // 凭证数据
            jfGrid1 = $('#pzGrid').jfGrid({
                headData: [
                    {label: '单位', name: 'companyName', width: 160, align: 'left'},
                    {label: "会计年度", name: "kjnd", width: 70, align: "center"},
                    {label: '凭证日期', name: 'pzrq', width: 80, align: 'center'},
                    {label: '凭证号', name: 'pzh', width: 50, align: 'center'},
                    {label: "会计科目", name: "kjkmCodeAndName", width: 200, align: "left"},
                    {label: "经济分类", name: "jjflCodeAndName", width: 200, align: "left"},
                    {label: "收款单位名称", name: "skrName", width: 260, align: "left"},
                    {label: '摘要', name: 'zy', width: 260, align: 'left'},
                ],
                dblclick: function (row) {
                    var pzid = $('#pzGrid').jfGridValue('id');
                    var companyId = $("#companyId").lrselectGet();
                    if(!companyId && !!defaultCompanyId) {
                        companyId = defaultCompanyId;
                    }
                    learun.layerForm({
                        id: 'preview_detail' + pzid,
                        title: '联查凭证',
                        url: config.webportal_server + 'pages/finance/pz/view.html?keyValue=' + pzid + '&companyId=' + companyId + 'ztId=701&access_token=' + config.getToken().access_token,
                        width: 1200,
                        height: 800,
                        maxmin: true,
                        btn: null
                    });
                },
                height: 580
            });
        },
        initData: function () {
            if (!!keyValue) {
               page.search();
            }
            if (!!warnId) {
                $.ajax({
                    url: config.base_server() + 'auditmodelwarns/updateReadFlag?id=' + warnId + '&access_token=' + config.getToken().access_token,
                    type: "GET",
                    success: function (data) {
                    }
                });
            }
        },
        search: function (param) {
            $('#lr_form_bg').fadeIn();
            param = param || {};

            var companyId = $("#companyId").lrselectGet();
            if(!companyId && !!defaultCompanyId) {
                companyId = defaultCompanyId;
            }
            var zy = $("#zy").val();
            var pzrqStart = $("#pzrqStart").val();
            var pzrqEnd = $("#pzrqEnd").val();
            var pzhStart = $("#pzhStart").val();
            var pzhEnd = $("#pzhEnd").val();
            var jStart = $("#jStart").val();
            var jEnd = $("#jEnd").val();
            var dStart = $("#dStart").val();
            var dEnd = $("#dEnd").val();

            param.companyId = companyId;
            param.zy = zy;
            param.pzrqStart = pzrqStart;
            param.pzrqEnd = pzrqEnd;
            param.pzhStart = pzhStart;
            param.pzhEnd = pzhEnd;
            param.jStart = jStart;
            param.jEnd = jEnd;
            param.dStart = dStart;
            param.dEnd = dEnd;

            page.refreshData(param);
        },
        refreshData: function (param) {
            learun.httpAsync('GET', config.base_server() + 'auditmodels/previewResult?modelId=' + keyValue  + '&warnId=' + warnId + '&access_token=' + config.getToken().access_token, param, function (data) {
                $('#lr_form_bg').fadeOut();
                $('.lr-layout-wrap').lrSetFormData(data);
                $("#modelName").html(data.modelName);
                $('#pzGrid').jfGridSet('refreshdata', data.step1List);
            });
        }
    };

    page.init();
}
